




C Structure, Union, Enums Test 1

1) What is the similarity between a structure, union and enumeration?

All are useful in defining new data types
All are useful in defining new variable
All are useful in defining new structures
All are useful in defining new pointers

Show Answer

The correct option is (a).
Explanation:
A structure, enumeration and union all of them can be helpful in defining a new data types in C language.
It is used for creating new data types that holds all kinds of data type like int, char, float, array inside a user defined data type. So user can use new values and logic of operation in simple manner.

2) How will we free the allocated memory in a C program?

delete(var-name)
dalloc(var-name)
remove(var-name)
free(var-name)

Show Answer

The correct option is (d).
Explanation:
The built in function free(var-name) is used for free or clear the memory space. If we use free() the referred memory location can be released for the future use or other operations.
Therefore the  free(var-name)  is used for clear the allocated memory in a C program. 

 3) A union can be nested in a structure.

True
False

Show Answer

The correct option is (a).
Explanation:
In address mapping or allocation of structure, the program takes union as a one data type in it.
Therefore union can be nested in a structure statement is true.

4) What will be the output of the below program?

#include
main()
{	
   union abc {
      int a;
      char cha;
   }var;
   var.cha = 'A';
   printf("%d", var.a);
}


A
65
97
Garbage value

Show Answer

The correct option is (b).
Explanation:
The union variable share the common memory for all its elements 'a' gets 'A' whose ASCII value is 65.
The statement printf("%d", var.a); is used for printing the value 65 in output.
Therefore the output of the program is  65.

5) The elements of union and structure are always accessed using & operator.

Yes
No

Show Answer

The correct option is (b).
Explanation:
No, because the elements of union and structure are always accessed using dot(.) operator.













Please Share





